layui.define(['jquery','config','layer'],function(exports) {
    var $ = layui.jquery,
        $layer = layui.layer,
        $cfg = layui.config();
    
    var HTTP = function(){};
    HTTP.prototype.request = function (url,params) {
        var responseData;

        $.ajax({
            type: "POST",
            url: $cfg.config.baseUrl + url,
            data: params,
            dataType: "json",
            async: false,
            cache: false,
            success: function (data) {
                responseData = data;
            },
            error: function(xhr, error) {
                if(error){
                    responseData = null;
                    $layer.msg("请求出错：" + xhr.status);
                }
            }
        });

        if(responseData && responseData.errno==1001){
            location.href = responseData.obj;
        }

        return responseData;
    };

    var http = new HTTP();
    exports("http",function(option){
        return http;
    });
});
